<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('农事记录')"/>
    <style>
        .fixed-table-toolbar .bs-bars {
            width: 100%;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">

        <div class="col-sm-12 search-collapse">
            <div class="btn-group " style="margin: 0px auto;display: table;" role="group">
                <button type="button" class="top-link btn btn-sm btn-white">当天农事</button>
                <button type="button" class="top-link btn-sm btn-white">在执行</button>
                <button type="button" class="top-link btn-sm btn-primary">待执行</button>
            </div>

        </div>

        <div class="btn-group-sm " id="toolbar1" role="group">
            <h3 class="inline">工作内容：</h3>
        </div>
        <div class="col-sm-12 select-table table-striped ">
            <table id="bootstrap-table-1" data-mobile-responsive="true"></table>
        </div>
        <!--计划详情-->
        <div class="col-sm-12 search-collapse">
            <h3>计划详情：</h3>
            <div class="thumbnail col-sm-3" style="width: 140px; height: 140px;">
                <img class="standard-img" src="/img/profile.jpg">
            </div>
            <div class="col-sm-9">
                <div class="ibox-title">
                    <h4 class="stageName">生产阶段：</h4>
                </div>
                <div class="ibox-title">
                    <h4 class="inline">计划编号：</h4><span class="kv-v planCode">--</span>
                    <h4 class="inline">作物名称：</h4><span class="kv-v cropNameCn">--</span>
                    <h4 class="inline">作物品种：</h4><span class="kv-v cropVarietiesCn">--</span>
                    <h4 class="inline">计划时间：</h4><span class="kv-v planTime">--</span>
                </div>
                <!--<div class="btn-group ibox-title" role="group">
                    <button type="button" class="middle-link btn-sm btn-white">农事记录</button>
                    <button type="button" class="middle-link btn-sm btn-white">植保请求记录</button>
                    <button type="button" class="middle-link btn-sm btn-white">植保请求</button>
                    <button type="button" class="middle-link btn-sm btn-white">新增农资</button>
                    <button type="button" class="middle-link btn-sm btn-white">新增农事</button>
                    <button type="button" class="middle-link btn-sm btn-white">智能控制</button>
                </div>-->
            </div>
        </div>

    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncWorkLog:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncWorkLog:remove')}]];
    var prefix = ctx + "system/ncWorkLog";
    var planType = [[${type}]];
    $(function () {
        initTodayWorks();

        $('.top-link').click(function () {
            var index = $(this).index();
            switch (index) {
                case 0:
                    window.location.href = ctx + 'system/ncWorkLog?type=' + planType;
                    return;
                case 1:
                    window.location.href = ctx + 'system/ncWorkLog/ncWorkLogWorking?type=' + planType;
                    return;
                case 2:
                    window.location.href = ctx + 'system/ncWorkLog/ncWorkLogPreWorking?type=' + planType;
                    return;

            }
        })
    });

    var fillPlanDetail = function (row, $element) {
        //阶段
        var str = '阶段：';
        if (row.stages) {
            $(row.stages).each(function (i, e) {
                /*1:完成 2：执行中 3：未进入*/
                var color = '';
                if (i >= topColor.length) {
                    color = topColor[i - topColor.length];
                } else {
                    color = topColor[i];
                }
                if (e.stageStatus == 1) {
                    str += '<span class="finished" style="background-color: '+color+'">' + e.stageName + '</span>'
                } else if (e.stageStatus == 2) {
                    str += '<span class="working" style="background-color: '+color+'">' + e.stageName + '<i class="fa fa-circle text-danger" style="margin-left: 2px"></i></span>'
                } else if (e.stageStatus == 3) {
                    str += '<span class="pre-working" style="background-color: '+color+'">' + e.stageName + '</span>'
                }

            });
        }
        if (!row) {
            row = {};
        }

        $('.stageName').html(str);
        $('.planCode').html(row.planCode);
        $('.cropNameCn').html(row.cropNameCn);
        $('.cropVarietiesCn').html(row.cropVarietiesCn);
        $('.planTime').html(dateFtt(row.planTime));

        if (row.standard && row.standard.pic) {
            $('.standard-img').attr('src', row.standard.pic)
        } else {
            $('.standard-img').attr('src', '/img/profile.jpg')
        }

    }

    /*初始化当天工作*/
    function initTodayWorks() {
        var prefix = ctx + "system/ncWork";

        var options = {
            url: prefix + "/listpreExe?planType="+planType,
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "标准农事",
            id: 'bootstrap-table-1',
            pageSize: 8,
            toolbar: 'toolbar1',
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            showExport: false,
            sortName:'plan_time',
            sortOrder:'asc',
            onClickRow: fillPlanDetail,
            onLoadSuccess: function (data) {
                if (data.rows.length > 0) {
                    fillPlanDetail(data.rows[0]);
                }
            },
            columns: [{
                title: '序号',
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
                {
                    field: 'planId',
                    title: '计划id',
                    visible: false
                },
                {
                    field: 'planCode',
                    title: '计划编号',
                    sortable: true
                },
                {
                    field: 'cropNameCn',
                    title: '作物名称',
                },
                {
                    field: 'cropVarietiesCn',
                    title: '作物品种',
                },
                {
                    field: 'planTime',
                    title: '计划执行时间',
                    formatter: function (value, row, index) {
                        return dateFtt(value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="preFinish(\'' + row.planId + '\')"><i class="fa fa-edit"></i>提前</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="delayFinish(\'' + row.planId + '\')"><i class="fa fa-edit"></i>推迟</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    /*提前计划*/
    function preFinish(planId) {
        var url = ctx + 'system/ncWork/preDays/' + planId;
        $.modal.open('计划提前', url);
    }

    /*推迟计划*/
    function delayFinish(planId) {
        var url = ctx + 'system/ncWork/delayDays/' + planId;
        $.modal.open('计划推迟', url);
    }

    if(planType == 1){
        setTitle("育苗管理-待执行",false)
    }else {
        setTitle("温室管理-待执行",false)
    }

    function reload() {
        $.table.refresh();
    }
</script>
</body>
</html>